package com.itheima.mq.rabbitmq.configuration;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
public class DlxExchangeConfiguretion {

    //声明死信交换机
    @Bean(name = "dlx.exchange")
    public Exchange dlxExchange() {
        return  ExchangeBuilder.directExchange("dlx.exchange").durable(true).build() ;
    }

    // 声明死信队列
    @Bean(name = "dlx.queue")
    public Queue dlxQueue() {
     return QueueBuilder.durable("dlx.queue").build() ;
    }

    //队列和交换机绑定
    @Bean
    public Binding dlxQueueBindToDlxExchange(@Qualifier(value = "dlx.exchange") Exchange exchange , @Qualifier(value = "dlx.queue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("dlx").noargs() ;
    }
}
